/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * leafget
 * Copyright (C) xinliGG 2008 <xinliGG@gmail.com>
 * 
 * leafget is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * leafget is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <iostream>

#include <unistd.h>

#include <gtkmm/stock.h>

#include "msg.h"

 Msg::Msg ( Gtk::Window &win, const std::string &title, const std::string &msg, const bool &show_cancel )
	: Gtk::Dialog ( title, win, false, false ),LabelMSG( msg, false )
{
	set_size_request( 400, 120 );
	set_resizable( false );
	
	boxMSG = get_vbox();
	boxMSG->set_homogeneous( false );
	boxMSG->set_spacing( 0 );
	
	boxMSG->pack_start( LabelMSG, Gtk::PACK_SHRINK, 0 );
	
	if( show_cancel )
		add_button( Gtk::Stock::CANCEL, 0 );
	add_button( Gtk::Stock::OK, 1 );

	set_default_response( 1 );	
	activate_default();
}


const int Msg::run_msg ( void )
{
	awser = 1;
	timer_on = true;

	run_timer = Glib::signal_timeout().connect( sigc::mem_fun( *this, &Msg::on_run_timer ), 0 );

	while( timer_on )
		usleep( 50 );

	return awser;
}

bool Msg::on_run_timer ( void )
{
	show_all_children();
	awser = run();

	timer_on = false;
	run_timer.disconnect();

	return true;
}


/* EOF */

